package xyz.matrix.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import xyz.matrix.model.User;

public class UserDao {

	public User login(Connection con, User user) throws SQLException {
		String sql = "select * from t_user where userName=? and password=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, user.getPassword());
		User currentUser = null;
		ResultSet rs = pstmt.executeQuery();
		while (rs.next()) {
			currentUser = new User();
			currentUser.setUserName(rs.getString("userName"));
			currentUser.setPassword(rs.getString("password"));
		}
		return currentUser;
	}
}
